//
//  ChongZhiVC.m
//  BrushFace
//
//  Created by timer_q on 16/1/22.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "ChongZhiVC.h"
#import "MySceneModel.h"
#import "WeChat.h"
#import "AlertDialogHelper.h"

@interface ChongZhiVC ()
{
    __weak IBOutlet UIButton *chongzhiBtn;
    __weak IBOutlet UIImageView *imageVIew;

    __weak IBOutlet UITextField *inputText;

}
@property (nonatomic,strong)MySceneModel *reqmodel;
@end

@implementation ChongZhiVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navBar setTitle:@"充值"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    _reqmodel = [MySceneModel SceneModel];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)weChatBtnClick:(UIButton *)sender {
    if (sender.selected == YES) {
        imageVIew.hidden = NO;
        sender.selected = NO;
        [chongzhiBtn setBackgroundImage:[UIImage imageNamed:@"BlueButtonBackView"] forState:UIControlStateNormal];
    }else{
        imageVIew.hidden = YES;
        sender.selected = YES;
        [chongzhiBtn setBackgroundImage:[UIImage imageNamed:@"grayButtonBack"] forState:UIControlStateNormal];
    }
    
}
- (IBAction)chongzhiBtnClick:(id)sender {
    if ([inputText.text integerValue]==0) {
        [AlertDialogHelper showToast:@"充值金额不正确"];
        return;
    }
    if (![WXApi isWXAppInstalled]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您尚未安装微信，请安装后重新尝试" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return ;
    }
        [_reqmodel user_chargeMoneyWithMoney:inputText.text andCB:^(id output) {
            if ([[NSString stringWithFormat:@"%@",[output objectForKey:@"repayType"]] integerValue]==1) {
                [AlertDialogHelper showToast:[output objectForKey:@"errormsg"]];
                return ;
            }
            
            [[NSUserDefaults standardUserDefaults] setObject:@"CHONGZHI" forKey:@"PAY"];
            [[NSUserDefaults standardUserDefaults] setObject:inputText.text forKey:@"MONEY"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        [WeChat sendOrderToWeChatWithPartnerId:[output objectForKey:@"appId"] andPrepayId:[output objectForKey:@"packageStr"] andNonceStr:[output objectForKey:@"nonceSignPay"] andTimeStamp:[output objectForKey:@"timestampSignPay"] andSign:[output objectForKey:@"signatureSignPay"]];

    }];
}

@end
